<?php

ini_set('display_errors', 1);
error_reporting(-1);
require_once '/data/wwwroot/g_vendor/autoload.php';

use Biz\service\Goods;
use Biz\service\Sku;
use Biz\service\theParagraph\Store;


$fp = fopen("theParagraphGoods.csv", 'w');
$title = [
    '房间号',
    'GoodsId',
    '商品名称',
    '一级类目',
    '二级类目',
    '品牌',
    'skuId',
    'sku名称',
    'sku价格',
    'sku库存',
];

fputcsv($fp, $title);

$storeInfo = Store::getStoreInfo(1);

foreach ($storeInfo['index'] as $room) {
    $collocationInfo = Store::GetCollocationInfo($room['id']);
    foreach ($collocationInfo['goods'] as $goods) {
        $skuInfo = Sku::Sku4Order([$goods['sku_id']]);
        $goodsInfo = Goods::Goods($goods['id'], Goods::FIELDS_GROUP_DETAIL);
        fputcsv($fp, [
            $room['room_title'],
            $goods['id'],
            $goods['title'],
            $goods['category_id'],
            $goods['second_category_id'],
            $goodsInfo['brand_info']['name'],
            $goods['sku_id'],
            $skuInfo[$goods['sku_id']]['sku_desc'],
            $skuInfo[$goods['sku_id']]['ori_price'],
            $skuInfo[$goods['sku_id']]['actual_stock'],
        ]);
    }
}